Skip to content

src: add MakeCallback() taking an Environment - #66510

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
nigrosimone:makecallback-env
Nov 26, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
nigrosimone:makecallback-env

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

node::MakeCallback() looks up the Environment from the creation context of the callback on every call. This adds an overload that takes it: an addon calling into the same Environment many times (uWS calls one handler per request) takes it once with GetCurrentEnvironment() and passes it. The callback must belong to that Environment.

NODE_EXTERN v8::MaybeLocal<v8::Value> MakeCallback(Environment* env,
                                                   v8::Local<v8::Object> recv,
                                                   v8::Local<v8::Function> callback,
                                                   int argc,
                                                   v8::Local<v8::Value>* argv,
                                                   async_context asyncContext);

It uses the internal helper added in #66509. The new benchmark napi/make_callback_env runs both overloads in the same process: 133.0 to 118.9 ns at n=1e7 (+11.8%) and 130.6 to 124.5 ns at n=1e6 (+4.9%), with #66395 and #66500 underneath, Linux x64, one core.

This is new public API, the shape was discussed in nodejs/performance#24.

Disclosure: I used Opus 5.5 (Max) as coding assistant

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/node-api
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Oct 4, 2026
@legendecas legendecas added the node-api Issues and PRs related to Node-API. label Oct 9, 2026
@ronag

ronag commented Nov 9, 2026

Copy link
Copy Markdown
Member

Why still draft?

@nigrosimone

nigrosimone commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Now is ready

It adds public API, so I wanted the shape agreed first (nodejs/performance#24). It is on top of #66509. If the shape looks fine to you, I'll mark it ready.

@ronag
ronag requested review from anonrig, jasnell and mcollina November 9, 2026 15:41
@nigrosimone
nigrosimone force-pushed the makecallback-env branch 3 times, most recently from 0bf95f3 to c07db16 Compare November 9, 2026 17:22
node::MakeCallback() looks up the Environment from the creation context
of the callback on every call. An addon that calls into the same
Environment many times, a server calling one handler per request for
example, can now take it once with GetCurrentEnvironment() and pass it.
The callback must belong to that Environment.

Add a benchmark, napi/make_callback_env, comparing the two overloads.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. node-api Issues and PRs related to Node-API. and removed node-api Issues and PRs related to Node-API. labels Nov 26, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 26, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (fa49b13) to head (3278f89).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/api/callback.cc 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66510      +/-   ##
==========================================
- Coverage   92.59%   90.50%   -2.10%     
==========================================
  Files         433      805     +372     
  Lines      200382   285810   +85428     
  Branches    30786    55184   +24398     
==========================================
+ Hits       185553   258681   +73128     
- Misses      14486    17214    +2728     
- Partials      343     9915    +9572     
Files with missing lines Coverage Δ
src/node.h 92.15% <ø> (ø)
src/api/callback.cc 81.25% <0.00%> (ø)

... and 513 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. semver-minor PRs that contain new features and should be released in the next minor version. labels Nov 26, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 3872251 into nodejs:main Nov 26, 2026
93 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 3872251

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 26, 2026
@github-project-automation github-project-automation Bot moved this from Need Triage to Done in Node-API Team Project Nov 26, 2026
nigrosimone added a commit to nigrosimone/fulmine.js that referenced this pull request Nov 27, 2026
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. node-api Issues and PRs related to Node-API. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

Development

Successfully merging this pull request may close these issues.

6 participants